package com.sundablog.controller.backend.system.upms.user;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sundablog.pojo.AdminUser;
import com.sundablog.pojo.AdminUserRole;
import com.sundablog.result.BaseResult;
import com.sundablog.result.LayUiResult;
import com.sundablog.service.backend.system.upms.user.UserService;

/**
 * 管理员用户角色控制器
 * @ClassName:  UserController   
 * @Description:用户角色控制器   
 * @author: 哒哒 
 * @date:   2018年3月14日 下午7:10:35   
 *     
 * @Copyright: 2018 www.sundablog.com Inc. All rights reserved.
 */
@Controller
@RequestMapping("/backend/system/upms/user")
public class UserController {

	@Autowired
	public UserService userService;
	
	/**
	 * 管理员用户界面显示
	 * @Title: index   
	 * @Description: 管理员用户界面显示   
	 * @param: @return      
	 * @return: String      
	 * @throws
	 */
	@RequiresPermissions("backend_system_upms_user_index")
	@RequestMapping("/index")
	public String index() {
		return "backend/system/upms/user/index";
	}
	
	/**
	 * 管理员用户添加
	 * @Title: addIndex   
	 * @Description: 管理员用户添加 
	 * @param: @return      
	 * @return: String      
	 * @throws
	 */
	@RequiresPermissions("backend_system_upms_user_add")
	@RequestMapping("/add")
	public String addIndex() {
		return "backend/system/upms/user/add";
	}
	
	/**
	 * 删除管理员用户
	 * @Title: delectUser   
	 * @Description: 删除管理员用户
	 * @param: @param userId
	 * @param: @return      
	 * @return: BaseResult      
	 * @throws
	 */
	@RequiresPermissions("backend_system_upms_user_delectUser")
	@RequestMapping("/delectUser")
	@ResponseBody
	public BaseResult delectUser(int userId) {
		int i = userService.delectUser(userId);
		if (i > 0) {
			return BaseResult.build(200, BaseResult.delectSuccess); 
		} else {
			return BaseResult.build(209, BaseResult.delectFail);
		}
	}
	
	/**
	 * 管理员用户编辑
	 * @Title: editIndex   
	 * @Description: 管理员用户编辑
	 * @param: @return      
	 * @return: String      
	 * @throws
	 */
	@RequiresPermissions("backend_system_upms_user_edit")
	@RequestMapping("/edit")
	public String editIndex() {
		return "backend/system/upms/user/edit";
	}
	
	/**
	 * 禁用管理员用户
	 * @Title: updataDisableUserId   
	 * @Description: TODO(这里用一句话描述这个方法的作用)   
	 * @param: @param userId
	 * @param: @return      
	 * @return: BaseResult      
	 * @throws
	 */
	@RequiresPermissions("backend_system_upms_user_disable")
	@RequestMapping("/updataDisableUserId")
	@ResponseBody
	public BaseResult updataDisableUserId(int userId) {
		int i = userService.updataDisableUserId(userId);
		if (i > 0) {
			return BaseResult.build(200, BaseResult.updataSuccess);
		} else {
			return BaseResult.build(201, BaseResult.updataFail);
		}
	}
	
	
	/**
	 * 分页查询
	 * @Title: findPagingQuery   
	 * @Description: TODO(这里用一句话描述这个方法的作用)   
	 * @param: @param page
	 * @param: @param limit
	 * @param: @return      
	 * @return: LayUiResult      
	 * @throws
	 */
	@RequestMapping("/findPagingQuery")
	@ResponseBody
	public LayUiResult findPagingQuery(@RequestParam(value="page", defaultValue="1") int page,@RequestParam(value="limit", defaultValue="10") int limit) {
		LayUiResult result = userService.findPagingQuery(page, limit);
		return result;
	}
	
	/**
	 * 添加管理员
	 * @Title: addAdminUser   
	 * @Description: 添加管理员 
	 * @param: @param adminUser
	 * @param: @return      
	 * @return: BaseResult      
	 * @throws
	 */
	@RequestMapping("/addAdminUser")
	@ResponseBody
	public BaseResult addAdminUser(AdminUser adminUser,int roleId) {
		int i = userService.addAdminUser(adminUser,roleId);
		if (i > 0) {
			return BaseResult.build(200, BaseResult.addSuccess);
		} else {
			return BaseResult.build(209, BaseResult.addFail);
		}
	}
	
	/**
	 * 根据角色ID 获取用户角色关联的信息
	 * @Title: selectByUserId   
	 * @Description: 根据角色ID 获取用户角色关联的信息
	 * @param: @param userId
	 * @param: @return      
	 * @return: BaseResult      
	 * @throws
	 */
	@RequestMapping("/selectByUserId")
	@ResponseBody
	public BaseResult selectByUserId(int userId) {
		AdminUserRole userRole = userService.selectByUserId(userId);
		return BaseResult.build(200, "", userRole);
	}
	
	/**
	 * 根据用户ID查询管理员信息
	 * @Title: selectAdminUserByUserId   
	 * @Description: 根据用户ID查询管理员信息
	 * @param: @param userId
	 * @param: @return      
	 * @return: BaseResult      
	 * @throws
	 */
	@RequestMapping("/selectAdminUserByUserId")
	@ResponseBody
	public BaseResult selectAdminUserByUserId(int userId) {
		AdminUser adminUser = userService.selectAdminUserByUserId(userId);
		return BaseResult.build(200, "", adminUser);
	}
	
	/**
	 * 修改用户信息
	 * @Title: updataAdminUser   
	 * @Description: 修改用户信息
	 * @param: @param adminUser
	 * @param: @param roleId
	 * @param: @return      
	 * @return: BaseResult      
	 * @throws
	 */
	@RequestMapping("/updataAdminUser")
	@ResponseBody
	public BaseResult updataAdminUser(AdminUser adminUser,int roleId) {
		int i = userService.updataAdminUser(adminUser,roleId);
		if (i > 0) {
			return BaseResult.build(200, BaseResult.updataSuccess);
		} else {
			return BaseResult.build(209, BaseResult.updataFail);
		}
	}
	
	
	
	
	
}
